package com.sky.controller.admin;

import com.alibaba.druid.sql.visitor.functions.Char;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : Sonic
 * @version : 1.0
 * @createTime : 2024-12-02  22:54
 * @description :
 */

@RestController(value = "adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "Admin Shop Api")
public class ShopController {
    public static final String KEY  = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * @param: [status]
     * @return: com.sky.result.Result
     * @description: set shop status
     **/
    @PutMapping("/{status}")
    @ApiOperation("set shop status")
    public Result setStatus(@PathVariable Integer status) {
        log.info("###### set shop status:{}", status == 1 ? "shop open" : "shop close");
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(KEY, status);
        return Result.success();
    }

    /**
     * @param: []
     * @return: com.sky.result.Result<java.lang.Integer>
     * @description: get shop status
     **/
    @GetMapping("/status")
    @ApiOperation("get shop status")
    public Result<Integer> getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("###### get shop status:{}", status == 1 ? "shop open" : "shop close");
        return Result.success(status);
    }

}
